package com.ch.dream.tools;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;


public class AnimationHelper {
	
	/**
	 * 渐显
	 * @param 持续时间
	 * @return
	 */
	public static Animation show(long time){
		Animation animation = new AlphaAnimation(0,1);
		animation.setDuration(time);
		return animation;
	}
	
	/**
	 * 渐隐
	 * @param 持续时间
	 * @return
	 */
	public static Animation hide(long time){
		Animation animation = new AlphaAnimation(1,0);
		animation.setDuration(time);
		return animation;
	}
	
	/**
	 * 以自身中心为圆心收缩
	 * @param 持续时间
	 * @return
	 */
	public static Animation scaleIn(long time){
		Animation animation =new ScaleAnimation(1,0,1,0,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF,0.5f);
		animation.setDuration(time);
		return animation;
	}
	
	/**
	 * 以自身中心为圆心扩放
	 * @param 持续时间
	 * @return
	 */
	public static Animation scaleOut(long time){
		Animation animation =new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF,0.5f);
		animation.setDuration(time);
		return animation;
	}
	
	/**
	 * 以自身中心为圆心旋转
	 * @param 持续时间
	 * @param 旋转角度
	 * @return
	 */
	public static Animation rotateSelf(long time,float degree){
		Animation animation =new RotateAnimation(0,degree,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF,0.5f);
		animation.setDuration(time);
		animation.setFillAfter(true);
		return animation;
	}
	
	public static Animation move(long time,int fromX,int fromY){
		Animation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,fromX,Animation.RELATIVE_TO_SELF,0,Animation.
				RELATIVE_TO_SELF,fromY,Animation.RELATIVE_TO_SELF,0);
		animation.setDuration(time);
		return animation;
	}
}
